package com.zf.yichat.controller.member;

import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.model.MemberLevel;
import com.zf.yichat.model.MemberLevelPrivilege;
import com.zf.yichat.service.MemberLevelService;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *用户会员等级
 */
@Controller
@RequestMapping("memberLevel")
@Slf4j
public class MemberLevelController extends BaseController {


    @Autowired
    private MemberLevelService memberLevelService;



    /*******************页面访问开始********************************/

    /**
     * 用户VIP等级列表
     * @return
     */
    @RequestMapping("/index")
    public String userLevelIndex() {
        return "level/index";
    }

    /**
     * 新增用户VIP等级列表
     * @return
     */
    @RequestMapping("/add")
    public String userLevelAdd() {
        return "level/add";
    }

    /**
     * 编辑用户VIP等级列表
     * @return
     */
    @RequestMapping("/editLevel")
    public String userLevelEdit(Long id) {
        MemberLevel level = memberLevelService.selectLevelById(id);
        getRequest().setAttribute("level", level);
        return "level/edit";
    }
    /**
     * 用户VIP等级列表-特权
     * @return
     */
    @RequestMapping("/privilege/index")
    public String privilegeLevelIndex(Long id) {
        getRequest().setAttribute("levelId", id);
        return "level/privilege/index";
    }

    /**
     * 新增用户VIP等级列表-特权
     * @return
     */
    @RequestMapping("/privilege/add")
    public String privilegeLevelAdd(Long levelId) {
        getRequest().setAttribute("levelId", levelId);
        return "level/privilege/add";
    }

    /**
     * 编辑用户VIP等级列表-特权
     * @return
     */
    @RequestMapping("/privilege/editLevel")
    public String privilegeLevelEdit(Long id) {
        MemberLevelPrivilege levelPrivilege = memberLevelService.selectLevelPrivilegeById(id);
        getRequest().setAttribute("privilege", levelPrivilege);
        return "level/privilege/edit";
    }

    /*******************页面访问结束********************************/


    /**
     * 查询用户VIP等级列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/level/list")
    @ResponseBody
    public FsResponse levelList(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return memberLevelService.selectLevelList();

    };

    /**
     * 新增用户VIP等级列表
     * @param level
     * @return
     */
    @RequestMapping("/level/save")
    @ResponseBody
    public FsResponse save(MemberLevel level) {
        memberLevelService.addMemberLevel(level);
        return FsResponseGen.success();
    };

    /**
     * 编辑用户VIP等级列表
     * @param level
     * @return
     */
    @RequestMapping("/level/edit")
    @ResponseBody
    public FsResponse edit(MemberLevel level) {
        memberLevelService.editMemberLevel(level);
        return FsResponseGen.success();
    };


    /**
     * 删除用户VIP等级列表
     * @param id
     * @return
     */
    @RequestMapping("/level/delete")
    @ResponseBody
    public FsResponse delete(Integer id) {
        memberLevelService.deleteMemberLevel(id);
        return FsResponseGen.success();
    };

    /**
     * 查询用户VIP等级列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/levelPrivilege/list")
    @ResponseBody
    public FsResponse levelPrivilegeList(Integer page, Integer limit, Long levelId) {
        PageHelper.startPage(page, limit);
        return memberLevelService.selectLevelPrivilegeList(levelId);

    };

    /**
     * 新增用户VIP等级列表
     * @param level
     * @return
     */
    @RequestMapping("/levelPrivilege/save")
    @ResponseBody
    public FsResponse levelPrivilegeSave(MemberLevelPrivilege level) {
        memberLevelService.addMemberLevelPrivilege(level);
        return FsResponseGen.success();
    };

    /**
     * 编辑用户VIP等级列表
     * @param level
     * @return
     */
    @RequestMapping("/levelPrivilege/edit")
    @ResponseBody
    public FsResponse levelPrivilegeEdit(MemberLevelPrivilege level) {
        memberLevelService.editMemberLevelPrivilege(level);
        return FsResponseGen.success();
    };


    /**
     * 删除用户VIP等级列表
     * @param id
     * @return
     */
    @RequestMapping("/levelPrivilege/delete")
    @ResponseBody
    public FsResponse levelPrivilegeDelete(Integer id) {
        memberLevelService.deleteMemberLevelPrivilege(id);
        return FsResponseGen.success();
    };

}
